import sqlalchemy as sa
from sqlalchemy import orm
from unittest import TestCase

from cibynet.model import meta


class TestModel(TestCase):
  """Let us test our model.
  Automatically initialize the session, 
  and begin/rollback before and after each test.
  """
  
  def __init__(self, *args, **kwargs):
    #Session = orm.sessionmaker(bind=meta.engine, autocommit=False)
    self.session = meta.Session()
    TestCase.__init__(self, *args, **kwargs)
        
  def setUp(self):
    """Begin a nested session.
    """
    self.session.begin(nested=True)
    
  def tearDown(self):
    """Rollback the nested session.
    """
    self.session.rollback()
    self.session.close()